package com.yanqu.road.server.logic.activity.orewar.condition;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.orewar.OreWarActivityData;
import com.yanqu.road.server.manger.activity.orewar.OreWarActivityMgr;

import java.math.BigInteger;

public class OreWarActivityScoreRankCondition extends BaseOreWarActivityRankCondition {

    public OreWarActivityScoreRankCondition(GamePlayer player, OreWarActivityData activityData, ActivityConditionInfo conditionInfo) {
        super(player, activityData, conditionInfo);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.OreWarAcCoinOutPut.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.OreWarAcCoinOutPut.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return false;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        UnionRiseRankArgs args = (UnionRiseRankArgs) object;
        if(null != args) {
            //虽然结束了，但是还是会自动发奖励，所有以结束展示时间作为不触发的条件
            ActivityInfo activityInfo = OreWarActivityMgr.getOpenActivityInfo(activityData.getActivityId());
            if(null != activityInfo) {
                if (args.getType() == UnionRiseRankArgs.NOTIFY_TYPE_NORMAL) {
                    setValue(getValue().add(args.getValue()));
                    // 重新生成排行榜
                    if(getValue().compareTo(BigInteger.ZERO) > 0 ){
                        rankChange();
                    }
                }
            }
        }
    }
}
